package com.bmw.seckill.controller;

import com.bmw.seckill.model.SeckillAdmin;
import com.bmw.seckill.security.SecurityUtils;
import com.bmw.seckill.service.IAdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;

/**
 * @author 陈世泽~
 * @version 1.0
 */

@Controller
@RequestMapping(value = "/regist")
@ResponseBody
public class RegisetUser {
    
    @Autowired
    private IAdminService iAdminService;
    
    @RequestMapping(value = "/user")
    public HashMap userRegest(@RequestBody SeckillAdmin user) throws Exception{
        
        HashMap m = new HashMap();
        try{
            /**encode加密*/
            user.setPassword(SecurityUtils.encodePassword(user.getPassword()));
            Boolean u = iAdminService.insertUser(user);
            if (u==true){
                m.put("code", "success");
                m.put("msg","注册成功");
            }else {
                m.put("msg","error");
            }

        } catch (Exception e) {
            e.printStackTrace();
            m.put("msg","error");
        }

        return m;
        
    }
}
